<?php
require_once './buildCurl.php';
$res = json_decode(file_get_contents('php://input'), true);

$session = $res['session'];

$url = "http://211.82.48.36/student/teachingResources/classCurriculum/index";

$myCurl = new MyCurl($url, $session);
$result = $myCurl->getResult();
$httpCode = $myCurl->getHttpCode();

if ($httpCode != 200) {
    $arr = array('err' => 1);
    exit(json_encode($arr));
}

$dom = new DOMDocument();
@$dom->loadHTML($result);
$xpath = new DOMXPath($dom);
$data = $xpath->query("/html/body/div[4]/div[2]/div[2]/div/div[1]/form[1]/div/div[1]/div[6]/select/option");

$result_arr_0 = ['未选择'];
$result_arr_1 = [-1];


for ($i = 1; $i < $data->length; $i++) {
    $items = $data->item($i);
    $name = $items->nodeValue;
    $value = $items->getAttribute('value');

    $result_arr_0[] = $name;
    $result_arr_1[] = $value;
}

$result_arr = array($result_arr_0, $result_arr_1);

$arr = array('err' => 0, 'college' =>  $result_arr_0, 'college_id' =>  $result_arr_1);
exit(json_encode($arr));
